<template>
	<view class="page">
		<view class="fill">
			<image src="https://img.jinghushi.com/images/9/2024/06/HD3DoTYobRc2Aor4f42CxFGD4x4RbD.png" mode="widthFix" class="bg"></image>
			<view class="f_position">
				<view class="f_tit">商城购物</view>
				<view class="search">
					<view class="searchInput" @click="$navTo('/pages/taobao/search')">
						<icon type="search" size="14" color="#999"/>
						<text>复制商品链接搜优惠券</text>
					</view>
				</view>
				<view class="f_tip">复制商品链接搜索优惠券，最高返50%</view>
			</view>
		</view>
		<view class="d_content">
			<view class="big_cate">
				<view class="big_cate_item" @click="$navTo('/pages/taobao/typeShop?type=2')">
					<view class="logo">
						<image src="/static/taobao/dy.png" mode="widthFix"></image>
						<view class="b_tag">一分购</view>
					</view>
					<view>
						<view>抖音</view>
						<view class="b_tit">最高返50%</view>
					</view>
				</view>
				<view class="big_cate_item" @click="$navTo('/pages/taobao/typeShop?type=1')">
					<view class="logo">
						<image src="/static/taobao/pdd.png" mode="widthFix"></image>
						<view class="b_tag">省钱</view>
					</view>
					<view>
						<view>拼多多</view>
						<view class="b_tit">最高返50%</view>
					</view>
				</view>
			</view>
			<view id="page_wp">
				<view class="cate" :class="{'nav_pos':isFixed}">
					<scroll-view class="c_tag_list" scroll-x="true">
						<view class="c_tag"  @click="changebigCate(0)" :class="{'c_tag_active':bigcateActive==0}">推荐</view>
						<view class="c_tag" v-for="item in cateList" :class="{'c_tag_active':bigcateActive==item.menuid}" @click="changebigCate(item.menuid)">{{item.title}}</view>
					</scroll-view>
				</view>
			</view>
			<view class="list">
				<view class="item" v-for="items in 10">
					<view class="l_head">
						<view class="l_left">
							<image src="https://img.jinghushi.com/images/9/2024/06/S7lzJ9XrmeUjfmQbrFBobRMhlPpXSs.png"></image>
							<view class="clamp"><text>三只松鼠大牌会场大牌折扣</text></view>
						</view>
						<view class="l_btn">
							<view class="l_enter" @click="$navTo('./douyinHall')">进入会场</view>
							<view class="l_share">分享</view>
						</view>
					</view>
					<scroll-view scroll-x="true" class="l_list">
						<view class="i_item" v-for="item in 8">
							<image src="https://img.jinghushi.com/images/9/2024/06/S7lzJ9XrmeUjfmQbrFBobRMhlPpXSs.png"></image>
							<view class="clamp">稚优泉口红口红扣过</view>
							<view class="i_price">
								<view class="p_new"><text class="small">￥</text>68</view>
								<view class="p_old">￥99</view>
							</view>
						</view>
					</scroll-view>
				</view>
			</view>
			<view class="empty_loading">
				<image v-show="isloading" src="../../static/business/loading.gif" mode=""></image>
				<text v-show="isempty">没有更多了~</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isloading: false,
				isempty: false,
				bigcate: 2,//1拼多多 2抖音
				bigcateActive: 0,
				cateList: [],
				goodsList: [],
				page:0,
				isFixed: false,
			};
		},
		onPageScroll() {
			let query = uni.createSelectorQuery().in(this);
			query.select('#page_wp').boundingClientRect(data => {
				this.isFixed = data.top <= 0 ? true : false;
				if(data.top <= 0){
					uni.setNavigationBarColor({
						frontColor: '#000000',
						backgroundColor: '#f8f8fe'
					})
				}else{
					uni.setNavigationBarColor({
						frontColor: '#ffffff',
						backgroundColor: '#f8f8fe'
					})
				}
			}).exec();
		},
		onLoad(){
			this.getCate();
			if(uni.getStorageSync('token')){
				this.getClipContent();
			}
		},
		onShow(){
			if(!uni.getStorageSync('token')){
				uni.redirectTo({
					url: '/pages/public/login'
				})
			}
		},
		onReachBottom(){
			this.getList();
		},
		methods: {
			getClipContent(){
				uni.getClipboardData({
					success: function (res) {
						if(res.data!='getClipContent'&&res.data.length!=0){
							uni.showModal({
								title: '检测到剪贴板内容',
								content: res.data,
								confirmText: '立即搜索',
								success: function (ress) {
									if (ress.confirm) {
										uni.navigateTo({
											url: "/pages/taobao/search?keywords="+res.data
										})
									} else if (ress.cancel) {
										uni.hideToast()
									}
								}
							});
						}
					}
				});
			},
			changeBig(id){
				if(this.bigcate == id) return;
				this.bigcate = id;
				this.bigcateActive = 0;
				this.page = 0;
				this.cateList = [];
				this.goodsList = [];
				this.getCate();
			},
			changebigCate(id){
				if(this.bigcateActive == id) return;
				this.bigcateActive = id;
				this.page = 0;
				this.goodsList = [];
				this.getList();
			},
			
			getCate(){
				let php = '';
				if(this.bigcate==1){
					php = "duoduo";
				}else if (this.bigcate==2){
					php = "douyin";
				}
				this.$axios('index/goodscate', 'POST', php).then(res => {
					if(res.data.code==200){
						this.cateList = res.data.data;
						// this.bigcateActive = res.data.data[0].menuid;
						this.getList();
					}
				})
			},
			getList(){
				this.isempty = false;
				this.isloading = true;
				this.page++;
				let php = '';
				if(this.bigcate==1){
					php = "duoduo";
				}else if (this.bigcate==2){
					php = "douyin";
				}
				this.$axios('index/goodsList', 'POST', php,{
					page: this.page,
					cid: this.bigcateActive
				}).then(res => {
					this.isloading = false;
					if(res.data.code==200){
						this.goodsList = [...this.goodsList, ...res.data.data];
						this.isempty = res.data.data.length <= 0;
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page{
		background: #f4f4f4;
	}
	.fill{
		position: relative;
		.bg{
			width: 100%;
		}
		.f_position{
			position: absolute;
			top: calc(var(--status-bar-height) + 40rpx);
			text-align: center;
			width: 100%;
			.f_tit{
				font-size: 32rpx;
				font-weight: 600;
				color: #FFFFFF;
			}
			.search{
				width: 100%;
				left: 0;
				padding: 34rpx 20rpx;
				.searchInput{
					background: #fff;
					border-radius: 8rpx;
					color: #999;
					height: 60rpx;
					border-radius: 30rpx;
					display: flex;
					align-items: center;
					width: 100%;
					justify-content: center;
					text{
						margin-left: 12rpx;
					}
				}
			}
			.f_tip{
				color: #FFFFFF;
				opacity: .5;
			}
		}
	}
	.d_content{
		background: #FBF8FE;
		border-radius: 12rpx 12rpx 0rpx 0rpx;
		padding: 24rpx;
		margin-top: -60rpx;
		position: relative;
	}
	.big_cate{
		display: flex;
		justify-content: space-between;
		position: relative;
		.big_cate_item{
			text-align: center;
			color: #333;
			display: flex;
			align-items: center;
			background: #FFFFFF;
			border-radius: 12rpx;
			justify-content: center;
			padding: 40rpx 0;
			width: 340rpx;
			.logo{
				width: 86rpx;
				// margin: 20px auto 8rpx;
				position: relative;
				margin-right: 40rpx;
				image{
					width: 100%;
					display: block;
				}
				.b_tag{
					position: absolute;
					right: -30rpx;
					top: -10rpx;
					color: #fff;
					font-size: 16rpx;
					border-radius: 10rpx;
					border: 1rpx solid #ff7d7e;
					background: #ff233d;
					padding: 2rpx 4rpx;
					border-bottom-left-radius: 0;
				}
			}
			.b_tit{
				font-size: 22rpx;
				color: #999;
			}
		}
	}
	.cate{
		.c_tag_list{
			white-space: nowrap;
			padding: 30rpx 0;
			.c_tag{
				display: inline-block;
				color: #999999;
				margin-right: 30rpx;
				font-size: 28rpx;
				position: relative;
			}
			.c_tag_active{
				font-size: 32rpx;
				font-weight: 600;
				color: #333333;
				&::after{
					content: '';
					position: absolute;
					left: 50%;
					bottom: 2upx;
					transform: translateX(-50%);
					width: 100%;
					height: 8rpx;
					background: linear-gradient( 90deg, #BB2FF2 0%, #8615E1 100%);
					border-radius: 4rpx;
					opacity: .8;
				}
			}
		}
	}
	.nav_pos {
		background: #f8f8fe;
		position: fixed;
		top: 0;
		padding-top: calc(var(--status-bar-height) + 10rpx);
		width: 100%;
		z-index: 900;
		margin-left: -20rpx;
		margin-right: -20rpx;
		padding-left: 20rpx;
		padding-right: 20rpx;
	}
	.list{
		.item{
			padding: 20rpx;
			background: #FFFFFF;
			border-radius: 12rpx;
			margin-bottom: 20rpx;
			.l_head{
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 20rpx;
				.l_left{
					display: flex;
					align-items: center;
					width: calc(100% - 290rpx);
					image{
						width: 88rpx;
						height: 88rpx;
						border-radius: 12rpx;
						margin-right: 20rpx;
					}
					.clamp{
						font-weight: 600;
						width: calc(100% - 88rpx);
					}
				}
				.l_btn{
					display: flex;
					align-items: center;
					view{
						border-radius: 26rpx;
						height: 52rpx;
						line-height: 52rpx;
						text-align: center;
						font-size: 24rpx;
						font-weight: 600;
					}
					.l_enter{
						background: #F0E1FF;
						color: #8615E1;
						margin-right: 20rpx;
						width: 154rpx;
					}
					.l_share{
						background: #8615E1;
						color: #FFFFFF;
						width: 112rpx;
					}
				}
			}
			.l_list{
				white-space: nowrap;
				.i_item{
					margin-right: 20rpx;
					width: 160rpx;
					display: inline-block;
					image{
						width: 100%;
						height: 160rpx;
						border-radius: 12rpx;
					}
					.clamp{
						font-size: 24rpx;
						font-weight: 600;
					}
					.i_price{
						display: flex;
						align-items: center;
						.p_new{
							font-size: 32rpx;
							color: #AF141D;
							font-weight: bold;
							margin-right: 6rpx;
							.small{
								font-size: 24rpx;
							}
						}
						.p_old{
							color: #999999;
							font-size: 20rpx;
							text-decoration: line-through;
						}
					}
				}
			}
		}
	}
</style>
